import java.sql.Connection;
import java.sql.SQLException;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;

public class Main {

	@Resource(mappedName = "jdbc/Test1")
	static javax.sql.DataSource ds;
	
	//@PersistenceContext
	EntityManager em;

	@PersistenceUnit
	EntityManagerFactory emf;
	
	public static void main(String[] args) {
		Connection conn = null;
		try {
			if (ds != null) {
				System.out.println("not Null");
				conn = ds.getConnection();
				boolean b = conn.isValid(30); //wait 30 sec
				System.out.println("isValid: " + b);
				if (b) {
					//conn.createStatement();
				}
			} else {
				System.out.println("Null");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
		Main m = new Main();
		m.handleEm();
	}
	
	void handleEm() {
		System.out.println("Em: " + em != null);
		if (em != null) {
			
		}
		System.out.println("Emf: " + emf != null);
		if (emf != null) {
			
		}
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see java.lang.Object#Object()
	 */
	public Main() {
		super();
	}

}